package com.getword.web.controller.teacher;

import com.getword.security.SUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/teacher/article")
public class ArticleController {

    @GetMapping("/add.html")
    public String add(HttpServletRequest request) {
        request.setAttribute("navi", "add");
        return "teacher/article/add.html";
    }
    @GetMapping("/addVideo.html")
    public String addVideo(HttpServletRequest request) {
        request.setAttribute("navi", "add");
        return "teacher/article/addVideo.html";
    }

    @GetMapping("/details.html")
    public String details() {
        return "/teacher/article/details.html";
    }

    // 文章评论
    @GetMapping("/comment.html")
    public String comment(Long id, Model model){
        SUser user = (SUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        Long userId = user.getUserId();

//        Result result = articleService.getArticleById(id);
//        Map<String, Object> data = (Map<String, Object>) result.getData();
//        String content = (String) data.get("content");
//        Article article = (Article) data.get("article");
//        article.setContent(content);

//        model.addAttribute("article", article);
        return "teacher/article/comment.html";
    }


    // 文章管理
    @GetMapping("/articleManage.html")
    public String articleManage(HttpServletRequest request) {
        request.setAttribute("navi", "articleManage");
        return "teacher/article/articleManage.html";
    }

    @GetMapping("/edit.html")
    public String editArticle(HttpServletRequest request){
        return "teacher/article/editArticle.html";
    }

}
